﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace SmartEP.Model
{
    public class BaseModel:XMLModel
    {        
        #region Fields
        private string _tableName;
        private string _fieldId;
        #endregion

        #region Properties
        public string TableName
        {
            get
            {
                return _tableName;
            }
        }
        #endregion

        #region Constructors
        public BaseModel(string tableName)
        {
            this._tableName = tableName.Trim();
        }
        public BaseModel(string tableName, string fieldId)
        {
            this._tableName = tableName.Trim();
            this._fieldId = fieldId.Trim();
        }
        #endregion

        #region Public Methods
        public static object GetFieldValue(DataRowView row, string fieldName)
        {
            return (row.Row.Table.Columns.Contains(fieldName) ? row[fieldName] : null);
        }        
        public virtual DataSet GetAll()
        {
            if (this._tableName != "")
            {
                return SqlHelper.ExecuteDataset(DBConnection.Connection, CommandType.TableDirect, this._tableName);
            }

            return null;
        }
        public virtual DataSet GetStoreProcedureByName(string ProcedureName, params object[] Parameters)
        {
            return SqlHelper.ExecuteDataset(DBConnection.Connection, ProcedureName, Parameters);
        }

        #endregion


    }
}
